package gugga.tasks
{
	import gugga.eventHelpers.EventRethrower;
	import gugga.tasks.events.ProgressiveTaskEvent;
	import gugga.tasks.events.TaskEvent;
	
	[Event(name="start", type="TaskEvent")]
	[Event(name="interrupted", type="TaskEvent")]
	[Event(name="completed", type="TaskEvent")]
	[Event(name="progress", type="ProgressiveTaskEvent")]
	
	/**
	 * <code>WrappingProgressiveTask</code> is designed to wrap an <code>IProgressiveTask</code>.
	 * 
	 * @see gugga.tasks.WrappingTask
	 */
	public class WrappingProgressiveTask extends WrappingTask implements IProgressiveTask 
	{
		public override function set WrappedTask(aValue : ITask) : void 
		{ 
			super.WrappedTask = aValue;
			
			if(mProgressRethrower != null)
			{
				mProgressRethrower.stopListening();
			}
			
			if(mWrappedTask)
			{ 		 
				mProgressRethrower = EventRethrower.create(this, mWrappedTask, ProgressiveTaskEvent.PROGRESS);
			}
		}	
		
		private var mProgressRethrower : EventRethrower;	
		
		public function WrappingProgressiveTask(aWrappedTask : IProgressiveTask) 
		{
			super(aWrappedTask);
		}
	
		public function getProgress() : Number 
		{
			return IProgressiveTask(mWrappedTask).getProgress();
		}
	}
}